package com.example.smartcity_ikun3.ui.home

import androidx.lifecycle.*
import com.example.smartcity_ikun3.logic.Repository
import com.example.smartcity_ikun3.logic.model.BannerModel
import com.example.smartcity_ikun3.logic.model.GetNewsUserModel
import com.example.smartcity_ikun3.logic.model.MoreModel
import com.example.smartcity_ikun3.logic.model.NewsModel

class HomeViewModel : ViewModel() {

    /**
     * Banner
     */
    private val banner: MutableLiveData<String> = MutableLiveData()
    val bannerList = ArrayList<BannerModel.RowsDTO>()
    val bannerLiveData = Transformations.switchMap(banner){
        Repository.getBanner()
    }
    fun setBanner(map: String){
        banner.value = map
    }


    /**
     * 新闻
     */
    private val news: MutableLiveData<Int> = MutableLiveData()
    val newsList = ArrayList<NewsModel.RowsDTO>()
    val newsLiveData = Transformations.switchMap(news){ query ->
        Repository.getNews(query, null, null)
    }
    fun setNews(id: Int?){
        news.value = id
    }

    /**
     * 根据ID查找新闻
     */
    private val newsId: MutableLiveData<Int?> = MutableLiveData()
    val newsListId = ArrayList<NewsModel.RowsDTO>()
    val newsLiveDataId = Transformations.switchMap(newsId){ query ->
        Repository.getNews(null, query, null)
    }
    fun setNewsId(id: Int?){
        newsId.value = id
    }

    /**
     * 根据Hot查找新闻
     */
    private val newsHot: MutableLiveData<String> = MutableLiveData()
    val newsListHot = ArrayList<NewsModel.RowsDTO>()
    val newsLiveDataHot = Transformations.switchMap(newsHot){ query ->
        Repository.getNews(null, null, query)
    }
    fun setNewsHot(hot: String?){
        newsHot.value = hot
    }



    /**
     * 新闻评论列表
     */
    private val getMore : MutableLiveData<Int> = MutableLiveData()
    val getMoreList = ArrayList<MoreModel.DataDTO>()
    val getMoreLiveData = Transformations.switchMap(getMore){
        Repository.getMore()
    }
    fun setGetMore(id: Int){
        getMore.value = id
    }
}